package com.cc.visitor.config;

import com.cc.alltype.BusinessException;
import com.cc.alltype.ResponseResult;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author chanchaw
 * @create 2024-09-19 12:50
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    @ResponseStatus(HttpStatus.OK)
    public ResponseResult handleBusinessException(BusinessException ex) {
        String msg = ex.getMsg();
        return ResponseResult.error(msg);
    }

    //@ResponseStatus(HttpStatus.BAD_REQUEST)
    @ResponseBody
    @ExceptionHandler(value = HttpMessageNotReadableException.class)
    @ResponseStatus(HttpStatus.OK)
    public ResponseResult handleValidException(HttpMessageNotReadableException exception) {
        return ResponseResult.error(exception.getMessage());
    }
}
